﻿using System;
using System.Diagnostics;
using NUnit.Framework;
using Laminar.Common.Maps;

namespace Laminar.Common.Maps.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestFixture]
    public class Maps
    {

        [Test]
        public void DistanceSamePoint0()
        {
            var distance = Helper.Distance(new Coordinate() { Latitude = 90, Longitude = -90 },
                                           new Coordinate() { Latitude = 90, Longitude = -90 }, UnitsOfLength.Mile);

            Assert.AreEqual(0, distance, "");

        }

        [Test]
        public void DistanceSampleDataNauticalMiles()
        {
            var distance = Helper.Distance(new Coordinate() { Latitude = 45, Longitude = 0 },
                                           new Coordinate() { Latitude = 0, Longitude = 45 }, UnitsOfLength.NauticalMiles);

            Assert.AreEqual(3599.8653599999993d, distance, "");
        }


        [Test]
        public void DistanceSampleDataMiles()
        {
            var distance = Helper.Distance(new Coordinate() { Latitude = 45, Longitude = 0 },
                                           new Coordinate() { Latitude = 0, Longitude = 45 }, UnitsOfLength.Mile);

            Assert.AreEqual(4145.3999999999996d, distance, "");
        }

        [Test]
        public void DistanceSampleDataKilometer()
        {
            var distance = Helper.Distance(new Coordinate() { Latitude = 45, Longitude = 0 },
                                           new Coordinate() { Latitude = 0, Longitude = 45 }, UnitsOfLength.Kilometer);

            Assert.AreEqual(6671.3746175999995d, distance, "");
        }

        [Test]
        public void BearingsTests()
        {
            var bearing = Helper.Bearing(new Coordinate() { Latitude = 45, Longitude = 1 },
                                         new Coordinate() { Latitude = 45, Longitude = 0 });

            Assert.AreEqual(270.35355787806577d, bearing, "");
            Assert.AreEqual(CardinalPoints.W, bearing.ToCardinalMark());

        }

        [Test]
        public void CardinalMarkValues()
        {
            Assert.AreEqual(CardinalPoints.N, 2D.ToCardinalMark());
            Assert.AreEqual(CardinalPoints.NE, 46D.ToCardinalMark());
            Assert.AreEqual(CardinalPoints.SE, 120D.ToCardinalMark());
            Assert.AreEqual(CardinalPoints.S, 170D.ToCardinalMark());
            Assert.AreEqual(CardinalPoints.SW, 220D.ToCardinalMark());
            Assert.AreEqual(CardinalPoints.W, 273D.ToCardinalMark());
            Assert.AreEqual(CardinalPoints.NW, 320D.ToCardinalMark());

        }



        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void ToCardinalMarkOutOfRange() { 390D.ToCardinalMark(); }

        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void CoordinateLatitudeGreater90() { var coordinate = new Coordinate() { Latitude = 100, Longitude = -90 }; }

        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void CoordinateLatitudeLessN90() { var coordinate = new Coordinate() { Latitude = -91, Longitude = -90 }; }

        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void CoordinateLongitudeGreater180() { var coordinate = new Coordinate() { Latitude = 90, Longitude = 190 }; }

        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void CoordinateLongitudeLessN180() { var coordinate = new Coordinate() { Latitude = 90, Longitude = -190 }; }


    }
}